package com.cyou.qb.front.startup;


import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.cyou.nad.utils.jmx.MyCacheUtils;
import com.cyou.qb.common.service.cache.StartUpCacheLoadCacheImpl;
import com.cyou.qb.constants.Constants;

public class StartupListener extends ContextLoaderListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent event) {
		
		super.contextInitialized(event);
			
		
		ServletContext context = event.getServletContext();
		ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		Constants.ctx = ctx;
		System.out.println("抢吧前台系统正在启动.....");
		//加载cache
//		System.out.println("Cache清理 .....");
		//需要清理所有Cache
		//MyCacheUtils.clearAllCache("");
//		System.out.println("Cache清理结束");
		System.out.println("Cache加载中.....");
		StartUpCacheLoadCacheImpl startUpCacheLoadCacheImpl = (StartUpCacheLoadCacheImpl) ctx.getBean("startUpCacheLoadCacheImpl");
		startUpCacheLoadCacheImpl.setActiveBasicInfo();
		startUpCacheLoadCacheImpl.setAssignedWinnerCache();
		startUpCacheLoadCacheImpl.setBlackListCache();
		System.out.println("Cache加载完成");
	}
	
}
